﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VirtualDrum.lib.db
{
	abstract class ControlDatabase
	{
		/// <summary>
		/// 数据库操作类唯一实例
		/// </summary>
		protected static ControlDatabase objCDB = null;

		/// <summary>
		/// 用于lock的辅助对象
		/// </summary>
		protected static readonly object obj = new object();

		/// <summary>
		/// sql 执行语句
		/// </summary>
		protected string _sql;

		/// <summary>
		/// 结果集列表对象 
		/// </summary>
		protected IList<string []> _objResultAL;

		/// <summary>
		/// 构造函数
		/// </summary>
		protected ControlDatabase()
		{			
			this._sql = "";
			this._objResultAL = new List<string[]>();
			this.getDBConnect();
		}
		/// <summary>
		/// 得到数据库连接对象
		/// </summary>
		protected abstract void getDBConnect();

		/// <summary>
		/// 得到数据库执行命令对象
		/// </summary>
		/// <param name="sql"></param>
		protected abstract void getDbCommand(string sql);

		/// <summary>
		/// 执行有结果集返回的查询,如select
		/// </summary>
		/// <param name="sql"></param>
		/// <returns></returns>
		public abstract IList<string []> executeQuery(string sql);

		/// <summary>
		/// 执行没有结果集的查询,如update,insert
		/// </summary>
		/// <param name="sql"></param>
		/// <returns></returns>
		public abstract int executeNonQuery(string sql);

		/// <summary>
		/// 生成数据集列表
		/// </summary>
		/// <returns></returns>
		protected abstract IList<string[]> makeResultArrayList();

		/// <summary>
		/// 关闭当前数据库连接
		/// </summary>
		public abstract void closeConnection();

		/// <summary>
		/// 从配置文件里得到连接数据库信息
		/// </summary>
		/// <returns></returns>
		protected abstract string getConnString() ;

		/// <summary>
		/// 得到系统当前时间
		/// </summary>
		/// <returns></returns>
		public abstract string getDateTime();
	}
}
